package com.bawei.lib_net

import com.bawei.lib_net.intercepteor.HttpHeadInterceptor
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
import javax.inject.Qualifier
import javax.inject.Singleton

/**
 *author：yjk
 *description:
 *date：2025/6/9
*/
@Module
@InstallIn(SingletonComponent::class)
object NetModule {

    @Provides
    @Singleton
    @CommonOkHttpClient
    fun provideOkHttpClient(): OkHttpClient {
        val interceptor = HttpLoggingInterceptor()
        if (true){
            interceptor.level = HttpLoggingInterceptor.Level.BODY
        }
        return OkHttpClient.Builder()
            .readTimeout(60, TimeUnit.SECONDS)
            .writeTimeout(60, TimeUnit.SECONDS)
            .connectTimeout(60, TimeUnit.SECONDS)
            .addInterceptor(HttpHeadInterceptor())
            .addInterceptor(interceptor)
            .build()
    }

//    @Provides
//    @Singleton
//    @SignOkHttpClient
//    fun provideSignOkHttpClient(): OkHttpClient {
//        val interceptor = HttpLoggingInterceptor()
//        if (true){
//            interceptor.level = HttpLoggingInterceptor.Level.BODY
//        }
//        return OkHttpClient.Builder()
//            .readTimeout(60, TimeUnit.SECONDS)
//            .writeTimeout(60, TimeUnit.SECONDS)
//            .connectTimeout(60, TimeUnit.SECONDS)
//            .addInterceptor(HttpHeadInterceptor())
//            .addInterceptor(SignInterceptor())
//            .addInterceptor(interceptor)
//            .build()
//    }

    @Provides
    @Singleton
    @CommonRetrofit
    fun provideRetrofit(@CommonOkHttpClient client:OkHttpClient): Retrofit {
        return Retrofit.Builder()
            .baseUrl("http://10.161.9.80:2209/")
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
//    @Provides
//    @Singleton
//    @SignRetrofit
//    fun provideSignRetrofit(@SignOkHttpClient client:OkHttpClient):Retrofit{
//        return Retrofit.Builder()
//            .baseUrl("http://10.161.9.80:8886")
//            .client(client)
//            .addConverterFactory(GsonConverterFactory.create())
//            .build()
//    }

    /******限定符******/
    @Qualifier
    @Retention(AnnotationRetention.RUNTIME)
    annotation class CommonOkHttpClient


//    @Qualifier
//    @Retention(AnnotationRetention.RUNTIME)
//    annotation class SignOkHttpClient

    @Qualifier
    @Retention(AnnotationRetention.RUNTIME)
    annotation class CommonRetrofit

//    @Qualifier
//    @Retention(AnnotationRetention.RUNTIME)
//    annotation class SignRetrofit


}